package net.tensor.skynet.fragment

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import com.google.android.material.appbar.CollapsingToolbarLayout
import net.tensor.skynet.R
import net.tensor.skynet.common.user.entity.User
import net.tensor.skynet.entity.DataContainer

class ItemDetailFragment : Fragment() {

    private var item: User? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        arguments?.let {
            val mm = DataContainer.USER_ITEMS
            item = mm.filter { it1 -> it1.id == it["item_id"] }[0]
            activity?.findViewById<CollapsingToolbarLayout>(R.id.toolbar_layout)?.title = item?.name
        }
    }

    @SuppressLint("SetTextI18n")
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val rootView = inflater.inflate(R.layout.item_detail, container, false)

        item?.let {
            rootView.findViewById<TextView>(R.id.item_detail).text = "$it"
        }

        return rootView
    }

    companion object {
        const val ARG_ITEM_ID = "item_id"
    }
}